%
% ec_interp1.m
%
%  Form the 1D linear interpolation matrix for edge-centered variables.
%
% input  -- Nf = number of cell centers on the fine grid
% output -- Ip
%
function Ip = ec_interp1(Nf);
  
  % number of centers on the coarse grid
  %
  Nc = Nf/2;
  
  % numbers of fine and course unknowns
  %
  Nfe = Nf;
  Nce = Nc;
  
  % allocate space for the matrix
  %
  Ip = spalloc(Nfe,Nce,3*Nce);
  
  % loop over columns
  %
  for j=1:Nce
    jf = 2*j-1;  % the corresponding fine node.
    % the contribution of this coarse node to nearby fine nodes
    % this is for period MAC grids
    if j==1
        rows = [Nfe, jf, jf+1];
    else
        rows = [jf-1:jf+1];
    end
    Ip( rows, j ) = [1/2; 1; 1/2];
  end
